#include "syscall.h"


/* GLOBAL VARIABLES */
	int lock1;
	int lock2;
	int lock3;
	int cond1;
	int	cond2;
	int cond3;
	int mv1;
	int mv2;
	int mv3;

void testInitializer(){

	Printing("initializing everything!\n", ConsoleOutput, 0, 0);
	
	lock1 = 0;
	lock2 = 0;
	lock3 = 0;
	cond1 = 0;
	cond2 = 0;
	cond3 = 0;
	mv1 = 0;
	mv2 = 0;
	mv3 = 0;
	
	lock1 = CreateLock("lock1", 5);
	Printing("lock1 created!\n", ConsoleOutput, 0, 0);
	if(lock1 == 0){
		Printing("Error when trying to create lock 1!\n", ConsoleOutput, 0, 0);
	}
	lock2 = CreateLock("lock2", 5);
	Printing("lock2 created!\n", ConsoleOutput, 0, 0);
	if(lock2 == 0){
		Printing("Error when trying to create lock 2!\n", ConsoleOutput, 0, 0);
	}
	lock3 = CreateLock("lock3", 5);
	Printing("lock3 created!\n", ConsoleOutput, 0, 0);
	if(lock2 == 0){
		Printing("Error when trying to create lock 3!\n", ConsoleOutput, 0, 0);
	}
	
	cond1 = CreateCondition("cond1", 5);
	Printing("cond1 created!\n", ConsoleOutput, 0, 0);
	if(cond1 == 0){
		Printing("Error when trying to create cond1!\n", ConsoleOutput, 0, 0);
	}
	cond2 = CreateCondition("cond2", 5);
	Printing("cond2 created!\n", ConsoleOutput, 0, 0);
	if(cond2 == 0){
		Printing("Error when trying to create cond2!\n", ConsoleOutput, 0, 0);
	}
	cond3 = CreateCondition("cond2", 5);
	Printing("cond3 created!\n", ConsoleOutput, 0, 0);
	if(cond3 == 0){
		Printing("Error when trying to create cond3!\n", ConsoleOutput, 0, 0);
	}

	mv1 = CreateMonitor("mv1", 3);
	Printing("mv1 created!\n", ConsoleOutput, 0, 0);
	if(mv1 == -1){
		Printing("Error when trying to create mv1!\n", ConsoleOutput, 0, 0);
	}
	mv2 = CreateMonitor("mv2", 3);
	Printing("mv2 created!\n", ConsoleOutput, 0, 0);
	if(mv2 == -1){
		Printing("Error when trying to create mv2!\n", ConsoleOutput, 0, 0);
	}
	mv3 = CreateMonitor("mv3", 3);
	Printing("mv3 created!\n", ConsoleOutput, 0, 0);
	if(mv3 == -1){
		Printing("Error when trying to create mv3!\n", ConsoleOutput, 0, 0);
	}
}

int main(){
	testInitializer();
	
	Printing("T2: Attempting to acquire lock 1\n", ConsoleOutput, 0, 0);
	AcquireLock("lock1", 5);
	Printing("T2: Acquired lock 1, about to set monitor value to 1\n", ConsoleOutput, 0, 0);
	SetMonitor("mv1 ", 4, 1, 0);
	Printing("T2: Monitor value should be 1 now\n", ConsoleOutput, 0, 0);
	Signal("cond1", 5, "lock1", 5);
	Printing("T2: Signaled T1, about to release lock 1\n", ConsoleOutput, 0, 0);
	ReleaseLock("lock1", 5);
	Printing("T2: Releasd lock 1, about to exit\n", ConsoleOutput, 0, 0);
	
	Exit(0);
	
return;
}